﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <link href="~/css/shop.css" type="text/css" rel="stylesheet" />
    <link href="~/css/Sellerber.css" type="text/css" rel="stylesheet" />
    <link href="~/css/bkg_ui.css" type="text/css" rel="stylesheet" />
    <link href="~/font/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
    <script src="~/js/jquery-1.9.1.min.js" type="text/javascript"></script>
    <script src="~/js/Sellerber.js" type="text/javascript"></script>
    <script src="~/js/jquery.dataTables.min.js"></script>
    <script src="~/js/jquery.dataTables.bootstrap.js"></script>
    <script src="~/js/layer/layer.js" type="text/javascript"></script>
    <script src="~/js/laydate/laydate.js" type="text/javascript"></script>
    <script src="~/js/hsCheckData.js" type="text/javascript"></script>
    <!--[if lt IE 9]>
    <script src="js/html5shiv.js" type="text/javascript"></script>
    <script src="js/respond.min.js"></script>
    <script src="js/css3-mediaqueries.js"  type="text/javascript"></script>
      <![endif]-->
    <title>添加分类</title>
</head>

<body>
    <div class="margin inside_pages clearfix">
        <div class="add_style clearfix relative">
            <ul>
                <li class="clearfix"><label class="label_name col-xs-1"><i>*</i>分类名称：&nbsp;&nbsp;</label><div class="Add_content col-xs-11"><input name="" id="Name" type="text" class="col-xs-2" /></div></li>
                <li class="clearfix">
                <label class="label_name col-xs-1"><i>*</i>分类层级：&nbsp;&nbsp;</label>
                <div class="Add_content col-xs-11">
                    <select id="Level">
                        <option value="1">一级</option>
                        <option value="2">二级</option>
                        <option value="3">三级</option>
                    </select>
                </div>
                </li>
                <li class="clearfix">
                    <label class="label_name col-xs-1"><i>*</i>父级分类：&nbsp;&nbsp;</label>
                    <div class="Add_content col-xs-11">
                        <select id="Parent">

                        </select>
                    </div>
                </li>
            </ul>
            <div class="Button_operation btn_width">
                <input id="commit" class="btn button_btn bg-deep-blue" type="button" value="保存并添加">
                <button class="btn button_btn bg-gray" type="button">取消添加</button>
            </div>
        </div>
    </div>
</body>
</html>
<script>
    //获取父级下拉框
    var Parent = $("#Parent");
    //获取层级的ID
    var LevelId = $("#Level").val();
    if (LevelId == 1) {
        Parent.html("<option value='0'>顶级分类</option>");
    }
    //层级下拉框联动
    $("#Level").change(function () {
        //获取父级下拉框
        var Parent = $("#Parent");
        //获取层级的ID
        var LevelId = $("#Level").val();
        if (LevelId == 1) {
            Parent.html("<option value='0'>顶级分类</option>");
            return;
        }
        LevelId = LevelId - 1;
        $.ajax({
            url: "/Category/GetParent?LevelId=" + LevelId,
            type: "post",
            dataType: "json",
            contentType: "application/json",
            success: function (result) {
                var myHTML = "";
                Parent.html("");//赋值之前先清空
                $.each(result, function (i, data) {
                    myHTML += "<option value=" + data.Id + ">" + data.Name + "</option>";

                });
                Parent.append(myHTML);
            }
        })
    });

    //添加按钮点击事件
    $("#commit").click(function () {
        var data = {};
        data.Name = $("#Name").val();
        data.ParentId = $("#Parent").val();
        data.CategoryLevel = $("#Level").val();
        $.ajax({
            url: "/Category/AddCategory",
            type: "post",
            data:data,
            success: function (result) {
                if (result.Success) {
                    layer.msg('新增成功！',
                        {
                            icon: 1,
                            time: 2000,
                            shade: 0.2
                        }, function () {
                            window.location.href="/Home/Category"
                        });
                }
                else
                {
                    layer.msg('新增失败！',
                    {
                            icon: 1,
                            time: 2000,
                            shade: 0.2
                    });
                }
            }
        })
    });
</script>
